<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 手机短信接口
 */
class Dnsrecord extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $GodadyKey = null;
    protected $GodadySecret = null;
    protected $model = null;
    protected $apikey = null;
    protected $secretapikey = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Dnsrecord;
        $this->apikey = 'pk1_70fc33b60ae1c5800629e741faf9f3a21b4b118338e03a82a943f1232890ca79';
        $this->secretapikey = 'sk1_91c45073600bd16af2c730dcf7b6c91df365e5f156a402c152c320d716381367';
        $this->GodadyKey = '9EXf5Wz3XEE_XcfjLgi1ZiGJJJXVL9U8DF';
        $this->GodadySecret = 'BKusScpoZY3rTtx2qnSEVP';
    }

    /**
     * 导入godaddy活跃域名
     */
    public function godaddy()
    {
        $url = "https://api.godaddy.com/v1/domains/?statuses=ACTIVE";
        $data = $this->geturl($url);
        if($data){
            $data = json_decode($data,true);
        }
        //更新到数据库中
        foreach ($data as $k=>$v){
            $params['updatetime'] = time();
            $params['api_type'] = 1;
            $params['name'] = $v['domain'];
            $params['domainId'] = $v['domainId'];
            date_default_timezone_set('Asia/Shanghai');
            $params['expires'] = date('Y-m-d H:i:s',strtotime($v['expires']));

            $dnslistname = Db::name('dns_list')->where('name',$v['domain'])->find();
            if($dnslistname){
                Db::name('dns_list')->where('name',$v['domain'])->update($params);
            }else{
                $params['createtime'] = time();
                Db::name('dns_list')->insert($params, true);
            }
        }
        return $data;
    }

    /**
     * 导入namesilo活跃域名
     */
    public function namesilo()
    {
        $url = "https://www.namesilo.com/api/listDomains?version=1&type=xml&key=e3cb14574de6b93b6b5c3b&withBid=1&pageSize=100&page=1&skipExpired=1";
        //取出最近一百条数据
        $return = $this->geturl_namesilo($url);
        if($return){
            $return = $this->xmlToArray($return);
            $data = $return['reply']['domains']['domain'];
        }
        if(!empty($data)){
            //更新到数据库中
            foreach ($data as $k=>$v){
                $params['updatetime'] = time();
                $params['api_type'] = 2;
                $params['name'] = $v;
                $dnslistname = Db::name('dns_list')->where('name',$v)->find();
                if($dnslistname){
                    Db::name('dns_list')->where('name',$v)->update($params);
                }else{
                    $params['createtime'] = time();
                    Db::name('dns_list')->insert($params, true);
                }
            }
        }
        return $data;
    }

    function geturl_namesilo($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    public function geturl_namecheap($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    //XML转数组
    function xmlToArray($xml)
    {
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $values;
    }

    function geturl($url){
        $headerArray =array("Content-Type:application/json;","Authorization: sso-key ".$this->GodadyKey.":".$this->GodadySecret);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    /**
     * @return null
     * 1.验证站点以及域名正确性
     * 2.查找站点存在哪几个规则，并对接相应的接口api
     * 3.分别记录日志
     */
    public function determineWhichAPI($dnstype,$dnsinfo)
    {
        //如果是二级域名
        if($dnsinfo['dns_id'] == 0){
            $channel = Db::name('dns_channel')
                ->field("c.*,tc.type_id")
                ->alias('c')
                ->join('fa_dns_typechannel tc', 'c.id = tc.channel_id', 'left')
                ->join('fa_dns_type t', 'c.id = tc.type_id', 'left')
                ->where(['c.status' => 'normal', 'tc.type_id' => $dnstype['id']])
                ->order('weigh', 'desc')
                ->select();
            $result = array();
            foreach ($channel as $k=>$v){
                if($v['apitype'] == 1){
                    $result = $this->porkbunApicreate($v,$dnsinfo);//类型1是porkbun
                }elseif ($v['apitype'] == 2){
                    $result = $this->godaddyApicreate($v,$dnsinfo);//类型2是godaddy
                }elseif ($v['apitype'] == 3){
                    $result = $this->namesiloApicreate($v,$dnsinfo);//类型3是namesilo
                }elseif ($v['apitype'] == 4){
                    $result = $this->namecheapApicreate($v,$dnsinfo);//类型3是namesilo
                }else{
                    $result = true;//暂定
                }
            }
        }
        //二级域名暂时不做
//        else{
//            $channel = Db::name('dns_channel')
//                ->field("c.*,tc.type_id")
//                ->alias('c')
//                ->join('fa_dns_typechannel tc', 'c.id = tc.channel_id', 'left')
//                ->join('fa_dns_type t', 'c.id = tc.type_id', 'left')
//                ->where(['c.status' => 'normal', 'tc.type_id' => $dnstype['id']])
//                ->order('weigh', 'desc')
//                ->find();
//            if($channel['apitype'] == 1){
//                $result = $this->porkbunApicreate($channel,$dnsinfo);//类型1是porkbun
//            }elseif ($channel['apitype'] == 2){
//                $result = true;//godaddy二级域名暂定
//            }else{
//                $result = true;//暂定
//            }
//        }
        return $result;
    }

    /**
     * @return DNS 类型1是porkbun
     */
    public function porkbunApicreate($v,$dnsinfo)
    {
        $params = array();

        $params['createtime'] = time();
        $params['updatetime'] = time();
        $params['dns_id'] = $dnsinfo['id'];
        $params['name'] = $v['name'];
        $params['type'] = $v['type'];
        $params['ttl'] = $v['ttl'];
        $params['type_id'] = $v['type_id'];
        //主域名
        if($dnsinfo['dns_id'] == 0){
            $params['primary_domain_name'] = $dnsinfo['name'];
            $params['new_domain_name'] = $v['name'].'.'.$dnsinfo['name'];
        }else{
            //如果已经是二级域名 则不需要系统中的配置
            $dnsinfoname = explode('.',$dnsinfo['name']);
            $params['name'] = $dnsinfoname[0];
            $params['primary_domain_name'] = $dnsinfoname[1] .'.'. $dnsinfoname[2];
            $params['new_domain_name'] = $dnsinfo['name'];
        }
        //调用porkbunApi
        $infoid = $this->model->insertGetId($params);
        $params['info'] = '1.1.3.'.$infoid;
        $porkbunApi = $this->porkbunApi($params);
        //porkbunApi解析域名(功能暂定)
        if($porkbunApi['status'] == true){
            $params['status'] = 'normal';
            $params['parsing_id'] = $porkbunApi['data']['id'];
            //更新域名绑定系统
            Db::name('dns_list')->where('id', $dnsinfo['id'])->update(
                [
                    'type_id' => $v['type_id'],
                ]
            );
            //如果是一级域名，则相应的添加解析后的二级域名
            if($dnsinfo['dns_id'] == 0){
                $listinfo = Db::name('dns_list')->where('name', $params['new_domain_name'])->find();
                if(empty($listinfo)){
                    $data['name'] = $params['new_domain_name'];
                    $data['dns_id'] = $dnsinfo['id'];
                    $data['type_id'] = $v['type_id'];
                    $data['createtime'] = time();
                    $data['updatetime'] = time();
                    $ids = Db::name('dns_list')->insertGetId($data);
                    //成功后添加操作记录
                    $this->adddnsanalysis($v,$ids,$dnsinfo['type_id']);
                }else{
                    $this->adddnsanalysis($v,$listinfo['id'],$dnsinfo['type_id']);
                }
            }else{
                //成功后添加操作记录
                $this->adddnsanalysis($v,$dnsinfo['id'],$dnsinfo['type_id']);
            }
        }
        $params['parsing_information'] = $porkbunApi['msg'];
        //更新解析记录
        //更新域名绑定系统
        $result = Db::name('dns_record')->where('id', $infoid)->update($params);
        return $result;
    }

    /**
     * @return DNS 类型3是namesilo
     */
    public function namesiloApicreate($v,$dnsinfo)
    {
        $params = array();

        $params['createtime'] = time();
        $params['updatetime'] = time();
        $params['dns_id'] = $dnsinfo['id'];
        $params['name'] = $v['name'];
        $params['type'] = $v['type'];
        $params['ttl'] = $v['ttl'];
        $params['type_id'] = $v['type_id'];
        //主域名
        if($dnsinfo['dns_id'] == 0){
            $params['primary_domain_name'] = $dnsinfo['name'];
            $params['new_domain_name'] = $v['name'].'.'.$dnsinfo['name'];
        }else{
            //如果已经是二级域名 则不需要系统中的配置
            $dnsinfoname = explode('.',$dnsinfo['name']);
            $params['name'] = $dnsinfoname[0];
            $params['primary_domain_name'] = $dnsinfoname[1] .'.'. $dnsinfoname[2];
            $params['new_domain_name'] = $dnsinfo['name'];
        }
        //调用$namesiloApi
        $infoid = $this->model->insertGetId($params);
        $params['info'] = '1.1.3.'.$infoid;
        $namesiloApi = $this->namesiloApi($params);
        //namesiloApi解析域名(功能暂定)
        if($namesiloApi['status'] == true){
            $params['status'] = 'normal';
            //更新域名绑定系统
            Db::name('dns_list')->where('id', $dnsinfo['id'])->update(
                [
                    'type_id' => $v['type_id'],
                ]
            );
            //如果是一级域名，则相应的添加解析后的二级域名
            if($dnsinfo['dns_id'] == 0){
                $listinfo = Db::name('dns_list')->where('name', $params['new_domain_name'])->find();
                if(empty($listinfo)){
                    $data['name'] = $params['new_domain_name'];
                    $data['dns_id'] = $dnsinfo['id'];
                    $data['type_id'] = $v['type_id'];
                    $data['createtime'] = time();
                    $data['updatetime'] = time();
                    $ids = Db::name('dns_list')->insertGetId($data);
                    //成功后添加操作记录
                    $this->adddnsanalysis($v,$ids,$dnsinfo['type_id']);
                }else{
                    $this->adddnsanalysis($v,$listinfo['id'],$dnsinfo['type_id']);
                }
            }else{
                //成功后添加操作记录
                $this->adddnsanalysis($v,$dnsinfo['id'],$dnsinfo['type_id']);
            }
        }
        $params['parsing_information'] = $namesiloApi['msg'];
        //更新解析记录
        //更新域名绑定系统
        $result = Db::name('dns_record')->where('id', $infoid)->update($params);
        return $result;
    }

    /**
     * @return DNS 类型3是namesilo
     */
    public function namecheapApicreate($v,$dnsinfo)
    {
        $params = array();

        $params['createtime'] = time();
        $params['updatetime'] = time();
        $params['dns_id'] = $dnsinfo['id'];
        $params['name'] = $v['name'];
        $params['type'] = $v['type'];
        $params['ttl'] = $v['ttl'];
        $params['type_id'] = $v['type_id'];
        //主域名
        if($dnsinfo['dns_id'] == 0){
            $params['primary_domain_name'] = $dnsinfo['name'];
            $params['new_domain_name'] = $v['name'].'.'.$dnsinfo['name'];
        }else{
            //如果已经是二级域名 则不需要系统中的配置
            $dnsinfoname = explode('.',$dnsinfo['name']);
            $params['name'] = $dnsinfoname[0];
            $params['primary_domain_name'] = $dnsinfoname[1] .'.'. $dnsinfoname[2];
            $params['new_domain_name'] = $dnsinfo['name'];
        }
        //调用$namesiloApi
        $infoid = $this->model->insertGetId($params);
        $params['info'] = '1.1.4.'.$infoid;
        $namecheapApi = $this->namecheapApi($params);
        //namecheapApi解析域名(功能暂定)
        if($namecheapApi['status'] == true){
            $params['status'] = 'normal';
            //更新域名绑定系统
            Db::name('dns_list')->where('id', $dnsinfo['id'])->update(
                [
                    'type_id' => $v['type_id'],
                ]
            );
            //如果是一级域名，则相应的添加解析后的二级域名
            if($dnsinfo['dns_id'] == 0){
                $listinfo = Db::name('dns_list')->where('name', $params['new_domain_name'])->find();
                if(empty($listinfo)){
                    $data['name'] = $params['new_domain_name'];
                    $data['dns_id'] = $dnsinfo['id'];
                    $data['type_id'] = $v['type_id'];
                    $data['createtime'] = time();
                    $data['updatetime'] = time();
                    $ids = Db::name('dns_list')->insertGetId($data);
                    //成功后添加操作记录
                    $this->adddnsanalysis($v,$ids,$dnsinfo['type_id']);
                }else{
                    $this->adddnsanalysis($v,$listinfo['id'],$dnsinfo['type_id']);
                }
            }else{
                //成功后添加操作记录
                $this->adddnsanalysis($v,$dnsinfo['id'],$dnsinfo['type_id']);
            }
        }
        $params['parsing_information'] = $namecheapApi['msg'];
        //更新解析记录
        //更新域名绑定系统
        $result = Db::name('dns_record')->where('id', $infoid)->update($params);
        return $result;
    }

    /**
     * @return DNS 类型2是godaddy
     */
    public function godaddyApicreate($v,$dnsinfo)
    {
        $params = array();
        $params['createtime'] = time();
        $params['updatetime'] = time();
        $params['dns_id'] = $dnsinfo['id'];
        $params['name'] = $v['name'];
        $params['type'] = $v['type'];
        $params['ttl'] = $v['ttl'];
        $params['type_id'] = $v['type_id'];
        $params['ip'] = $v['ip'];
        //主域名
        if($dnsinfo['dns_id'] == 0){
            $params['primary_domain_name'] = $dnsinfo['name'];
            $params['new_domain_name'] = $v['name'].'.'.$dnsinfo['name'];
        }else{
            //如果已经是二级域名 则不需要系统中的配置
            $dnsinfoname = explode('.',$dnsinfo['name']);
            $params['name'] = $dnsinfoname[0];
            $params['primary_domain_name'] = $dnsinfoname[1] .'.'. $dnsinfoname[2];
            $params['new_domain_name'] = $dnsinfo['name'];
        }

        //调用godaddyApi
        $infoid = $this->model->insertGetId($params);
        $godaddyApi = $this->godaddyApi($params);
        if($godaddyApi['status'] == true){
            $params['status'] = 'normal';
            if(isset($godaddyApi['data']['id'])){
                $params['parsing_id'] = $godaddyApi['data']['id'];
            }
            //更新域名绑定系统
            Db::name('dns_list')->where('id', $dnsinfo['id'])->update(
                [
                    'type_id' => $v['type_id'],
                ]
            );
            //如果是一级域名，则相应的添加解析后的二级域名
            if($dnsinfo['dns_id'] == 0){
                $listinfo = Db::name('dns_list')->where('name', $params['new_domain_name'])->find();
                if(empty($listinfo)){
                    $data['name'] = $params['new_domain_name'];
                    $data['dns_id'] = $dnsinfo['id'];
                    $data['type_id'] = $v['type_id'];
                    $data['createtime'] = time();
                    $data['updatetime'] = time();
                    $ids = Db::name('dns_list')->insertGetId($data);
                    //成功后添加操作记录
                    $this->adddnsanalysis($v,$ids,$dnsinfo['type_id']);
                }else{
                    $this->adddnsanalysis($v,$listinfo['id'],$dnsinfo['type_id']);
                }
            }else{
                //成功后添加操作记录
                $this->adddnsanalysis($v,$dnsinfo['id'],$dnsinfo['type_id']);
            }
        }
        $params['parsing_information'] = $godaddyApi['msg'];
        //更新解析记录
        //更新域名绑定系统
        $result = Db::name('dns_record')->where('id', $infoid)->update($params);
        return $result;
    }

    /**
     * @return porkbunApi
     */
    public function porkbunApi($params)
    {
        $return['status'] = false;
        $return['msg'] = '参数错误';
        $return['data'] = $params;

        $arr['apikey'] = $this->apikey;
        $arr['secretapikey'] = $this->secretapikey;

        $arr['name'] = $params['name'];
        $arr['type'] = $params['type'];
        $arr['content'] = $params['info'];
        $arr['ttl'] = $params['ttl'];
//        查询是否重复
        $repeat = $this->repeatporkbunApi($params);
        if($repeat == false){
            $return['msg'] = '已有记录无需重复添加';
            return $return;
        }
        $url = 'https://porkbun.com/api/json/v3/dns/create/'.$params['primary_domain_name'];
        $data = $this->post_json_data($url,json_encode($arr));
        $data = json_decode($data,true);
        if($data['status'] == 'SUCCESS'){
            $return['status'] = true;
            $return['msg'] = '解析成功';
            $return['data'] = $data;
            return $return;
        }else{
            $return['msg'] = $data['message'];
            return $return;
        }

    }

    /**
     * @return porkbunApi
     */
    public function namecheapApi($params)
    {
        $return['status'] = false;
        $return['msg'] = '参数错误';
        $return['data'] = $params;
        $return = array();
        $primary_domain_name = array();
        if (!empty($params)) {
            $primary_domain_name = explode('.',$params);
        }
        $url = "http://api.namecheap.com/xml.response?ApiUser=waitingnow&ApiKey=6e42d68999274d458de43ca300ee3fbf&UserName=waitingnow&Command=namecheap.domains.dns.setHosts&ClientIp=27.18.218.10&SLD=".$primary_domain_name[0]."&TLD=".$primary_domain_name[1]."&HostName1=www&RecordType1=CNAME&Address1=name.shoplazza.store&TTL1=300&HostName2=@&RecordType2=A&Address2=172.65.227.72&TTL2=300";

        $returns = $this->geturl_namecheap($url);
        $data = array();
        if($returns){
            $returns = $this->xmlToArray($returns);
        }
        if($returns['@attributes']['Status'] == 'OK' && isset($returns['@attributes']['Status'])){
            $return['status'] = true;
            $return['msg'] = '解析成功';
            $return['data'] = $data;
//            return $return;
        }else{
            if (isset($returns['Errors']['Error'])) {
                $return = $params.'域名绑定错误：'.$returns['Errors']['Error'];
                return $return;
            } else {
//                return $return;
            }
        }
    }

    /**
     * @return namesiloApi
     */
    public function namesiloApi($params)
    {
        $return['status'] = false;
        $return['msg'] = '参数错误';
        $return['data'] = $params;

        $url = "https://www.namesilo.com/api/dnsAddRecord?version=1&type=xml&key=e3cb14574de6b93b6b5c3b&domain=".$params['primary_domain_name']."&rrtype=".$params['type']."&rrhost=".$params['name']."&rrvalue=".$params['info']."&rrttl=7207";
        //取出最近一百条数据
        $returns = $this->geturl_namesilo($url);
        if($returns){
            $returns = $this->xmlToArray($returns);
            if(isset($returns['reply']['detail']) && $returns['reply']['detail'] == 'success'){
                $return['status'] = true;
                $return['msg'] = '解析成功';
                return $return;
            }else{
                $return['msg'] = $return['msg'] = $returns['reply']['detail'];
                return $return;
            }
        }else{
            return $return;
        }

    }
    /**
     * @return null
     */
    public function adddnsanalysis($v,$id,$type_id)
    {
        $where['dns_id'] = $id;
        $where['type'] = 1;
        Db::name('dns_analysis')->where($where)->delete();

        $data1['dns_id'] = $id;
        $data1['type_id'] = $v['type_id'];
        $data1['channel_id'] = $v['id'];
        $data1['operating_instructions'] = '绑定域名';
        $data1['type'] = 1;
        $data1['createtime'] = time();
        $data1['updatetime'] = time();
        $return = Db::name('dns_analysis')->insert($data1, true);

        if($type_id > 0 && $type_id !== $v['type_id']){
            $where['dns_id'] = $id;
            $where['type'] = 2;
            Db::name('dns_analysis')->where($where)->delete();

            $data2['dns_id'] = $id;
            $data2['type_id'] = $type_id;
            $data2['channel_id'] = 0;
            $data2['operating_instructions'] = '删除域名';
            $data2['type'] = 2;
            $data2['createtime'] = time();
            $data2['updatetime'] = time();
            $return = Db::name('dns_analysis')->insert($data2, true);
        }
        return $return;
    }

    /**
     * @return godaddyApi
     */
    public function godaddyApi($params)
    {
        $return['status'] = false;
        $return['msg'] = '参数错误';
        $return['data'] = $params;
        $url = "https://api.godaddy.com/v1/domains/".$params['primary_domain_name']."/records/".$params['type'].'/'.$params['name'];
//        //接口2
//        $url = "https://api.godaddy.com/v1/domains/".$params['primary_domain_name']."/records";
        $arr_header[] = "Content-Type:application/json";
        //添加头，在name和pass处填写对应账号密码
        $arr_header[] = "Authorization: sso-key ".$this->GodadyKey.":".$this->GodadySecret;
        $records[0]['data'] = $params['ip'];
        $records[0]['ttl'] = $params['ttl'];
        $records[0]['port'] = 1;
//        //接口2
//        $records[0]['type'] = $params['type'];
//        $records[0]['name'] = $params['name'];

        //        查询是否重复
        $repeat = $this->repeatporkbunApi($params);
        if($repeat == false){
            $return['msg'] = '已有记录无需重复添加';
            return $return;
        }
        $data = $this->post_json_godaddyApi($url,json_encode($records),$arr_header);
        if(empty($data)){
            $return['status'] = true;
            $return['msg'] = '解析成功';
            $return['data'] = $data;
            return $return;
        }else{
            $data = json_decode($data,true);
            $return['msg'] = $data['message'];
            return $return;
        }
    }

    /**
     * 查询是否重复
     */
    public function repeatporkbunApi($params)
    {
        $list = $this->model
            ->where('primary_domain_name', '=', $params['primary_domain_name'])
            ->where('name', '=', $params['name'])
            ->where('type', '=', $params['type'])
            ->where('status', '=', 'normal')
            ->order('createtime desc')
            ->find();
        if(!empty($list['type_id']) && $list){
            if($list['type_id'] == $params['type_id']){
                return false;
            }else{
                return true;
            }
        }else{
            return true;
        }
    }

    /**
     * post 发送JSON 格式数据
     * @param $url string URL
     * @param $data_string string 请求的具体内容
     * @return array
     *      code 状态码
     *      result 返回结果
     */
    public function post_json_data($url, $data_string) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
        curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
//执行请求
        $output = curl_exec($ch);
//打印获得的数据
        curl_close($ch);
        return $output;
    }

    public function post_json_godaddyApi($url, $data_string,$arr_header=null) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        if(!empty($arr_header)){
            curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header);
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    public function testdns(){
        $url = "http://api.namecheap.com/xml.response?ApiUser=waitingnow&ApiKey=6e42d68999274d458de43ca300ee3fbf&UserName=waitingnow&Command=namecheap.domains.dns.setHosts&ClientIp=27.18.218.10&SLD=stockxsales&TLD=com&HostName1=www&RecordType1=CNAME&Address1=name.shoplazza.store&TTL1=300&HostName2=@&RecordType2=A&Address2=172.65.227.72&TTL2=300&HostName3=@&RecordType3=TXT&Address3=facebook-domain-verification=79k5embtpfpn206h61tqr6yx9lx11o&TTL3=100";
        $returns = $this->geturl_namecheap($url);
        if($returns){
            $returns = $this->xmlToArray($returns);
        }
        dump($returns);
        die;
    }
}
